package com.wg.sparkdemo.hive;

import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestHive8 {
	
	private static Logger logger = LoggerFactory.getLogger(TestHive8.class);

    public static void main(String[] args) throws ClassNotFoundException {
    	
    	
    	SparkSession spark = SparkSession.builder()
    			.config("hive.metastore.uris", "thrift://nsn-host135.nsn.com:9083")
    			.enableHiveSupport().appName("TestHive1")
    			.master("local[4]").getOrCreate();
    	
    	JavaSparkContext javaSparkContext = new JavaSparkContext(spark.sparkContext());
    	javaSparkContext.hadoopConfiguration().set("dfs.nameservices", "nj135cluster");
    	javaSparkContext.hadoopConfiguration().set("dfs.ha.namenodes." + "nj135cluster", "nn1,nn2");
    	javaSparkContext.hadoopConfiguration().set("dfs.namenode.rpc-address." + "nj135cluster" + ".nn1", "nsn-host135.nsn.com:8020");
    	javaSparkContext.hadoopConfiguration().set("dfs.namenode.rpc-address." + "nj135cluster" + ".nn2", "nsn-host134.nsn.com:8020");
    	javaSparkContext.hadoopConfiguration().set("dfs.client.failover.proxy.provider." + "nj135cluster", "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider");
    	
    	spark.sql("select * from HIVE_MODEL_A").show(10);
    }
}
